/* eslint-disable @typescript-eslint/no-var-requires */
const { themeDate } = require('wd-platform-library')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const autoprefixer = require('autoprefixer')
const pxtorem = require('postcss-pxtorem')
const { name } = require('./package.json')
const Timestamp = new Date().getTime()
module.exports = {
    // publicPath: '/',
    // publicPath: process.env.NODE_ENV + '' === "'development'" ? '/' : '/fantMicro/auth/',
    outputDir: process.env.outputDir, // 打包文件输出
    devServer: {
        port: 8080,
        host: '0.0.0.0',
        open: false, // 启动后是否自动打开网页
        headers: { // 重点1: 允许跨域访问子应用页面
            'Access-Control-Allow-Origin': '*'
        }
    },
    css: {
        loaderOptions: {
            less: { // 修改antd的颜色配置
                lessOptions: {
                    modifyVars: themeDate,
                    javascriptEnabled: true
                }
            },
            scss: {
                // sass-loader版本V8以上
                prependData: '@import "wd-platform-library/lib/es/variable.scss";'
            },
            postcss: {
                plugins: [
                    autoprefixer(),
                    pxtorem({
                        rootValue: 100,
                        propList: ['*'],
                        // minPixelValue: 12, //px小于12的不会被转换
                        // 保留rem小数点多少位
                        unitPrecision: 5
                    })
                ]
            }
        }
    },
    lintOnSave: false, // 关闭eslint代码检查
    // 自定义webpack配置
    configureWebpack: {
        devtool: 'source-map',
        resolve: {
            alias: {
                '@': path.join(__dirname, 'src')
            }
        },
        output: {
            // 这里改成跟主应用中注册的一致
            library: 'auth',
            libraryTarget: 'umd',
            jsonpFunction: `webpackJsonp_${name}`,
            filename: `js/[name].${Timestamp}.js`,
            chunkFilename: `js/[name].${Timestamp}.js`
        },
        plugins: [
            new MiniCssExtractPlugin({
                // 修改打包后css文件名
                filename: `css/[name].${Timestamp}.css`,
                chunkFilename: `css/[name].${Timestamp}.css`
            })
        ]
    }
}